<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Notifications\Notifiable;

class Config extends Model
{
    use Notifiable;
    use SoftDeletes;
    /**
     * 需要转换成日期的属性
     *
     * @var array
     */
    protected $dates = ['deleted_at'];

    protected $table = 'configs';

    // 配置列表
    public static function getList($request)
    {
        $query = self::select('*');
        if (isset($request->code)) {
            $query->where('code', $request->code);
        }
        if (isset($request->status) && $request->status) {
            $query->where('status', $request->status);
        }
        if (isset($request->name) && $request->name) {
            $query->where('name', 'like', '%' . $request->name . '%');
        }
        $res = $query->paginate($request->size);
        return $res ? $res->toArray() : [];
    }

    // 配置详情
    public static function getInfoById($id)
    {
        $res = self::select('*')->where('id', $id)->first();
        return $res ? $res->toArray() : [];
    }

    // 配置详情
    public static function getInfoByCode($code)
    {
        $res = self::select('*')->where('code', $code)->first();
        return $res ? $res->toArray() : [];
    }

    // 删除配置
    public static function del($id)
    {
        $res = static::where('id', $id)->delete();
        return $res;
    }

}
